package com.cosc716.restaurant.domain;

import java.util.ArrayList;

public class CustomerGroup {
	public final static int MIN_CUSTOMERS = 0;
	public final static int MAX_CUSTOMERS = 8;
	
	private ArrayList<Customer> customers;
	private int arrivalTime = 0;
	
	public int getArrivalTime() {
		return arrivalTime;
	}

	public void setArrivalTime(int arrivalTime) {
		this.arrivalTime = arrivalTime;
	}

	public int getDepartureTime() {
		// All customers leave at the same time, so pick any customer and get the departure time
		Customer c = customers.get(0);
		return c.getDepartureTime();
	}

	public int getSize() {
		return customers.size();
	}

	public CustomerGroup() {
		customers = new ArrayList<Customer>();
	}

	public ArrayList<Customer> getCustomers() {
		return customers;
	}

	public boolean addCustomer(Customer customer) {
		if (customers.size() >= MAX_CUSTOMERS) {
			return false;
		}
		
		if (customers.add(customer)) {
			return true;
		}
		return false;
	}
	
	public boolean removeCustomer(Customer customer) {
		if (customers.size() <= MIN_CUSTOMERS) {
			return false;
		}
		
		if (customers.remove(customer)) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return "CustomerGroup [size=" + getSize() + ", arrivalTime=" + getArrivalTime()+ ", departureTime=" + getDepartureTime() +   "]";
	}
}
